﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Solidi
{
	/// <summary>
	/// Represents a registry for adding and finding dependencies.
	/// </summary>
	public interface IDependencyRegistry
	{
		/// <summary>
		/// Adds the specified dependencies to the registry.
		/// </summary>
		/// <param name="dependencies">The dependencies to add.</param>
		/// <remarks>
		/// Dependencies cannot be overwritten, they get added to the list of dependencies for a given key.
		/// The convention adopted by this library is that the last registration should "win" if only
		/// one registration is required for a given key. This convention should be followed by dependency resolvers.
		/// </remarks>
		void Add(IEnumerable<IDependency> dependencies);

		/// <summary>
		/// Finds the dependencies for the given key and optionally adds dependencies using the given function if none already exist.
		/// </summary>
		/// <param name="key">The key of the element to add.</param>
		/// <param name="dependencyFactory">The optional function used to generate a dependencies for the key if none exist.</param>
		/// <returns>The dependencies for the given key.</returns>
		/// <remarks>
		/// The optional function for generating dependencies is primarily useful for auto-registration
		/// where locating and optionally adding can be performed in an efficient, thread-safe way.
		/// </remarks>
		IEnumerable<IDependency> Find(IDependencyKey key, Func<IEnumerable<IDependency>> dependencyFactory);
	}
}
